/*
 * Copyright 2020 tu.cn All right reserved. This software is the
 * confidential and proprietary information of tu.cn ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Tu.cn
 */
package com.onedec.page.controller;

import com.onedec.entity.OnedecEmp;
import com.onedec.entity.OnedecSchedule;
import com.onedec.page.feign.ScheduleClient;
import com.onedec.utils.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 31014
 * @date 2020/7/10 14:30
 */
@RestController
@RequestMapping("schedule")
public class ScheduleController {
    @Autowired
    private ScheduleClient scheduleClient;

    @PostMapping
    public ResponseEntity insertSchedule(String date, String value,String title) {
        scheduleClient.insertSchedule(date, value,title);
        return ResponseEntity.SUCCESS;
    }

    @GetMapping
    public ResponseEntity selectSchedule(HttpServletRequest request) {
        final com.onedec.admin.entity.OnedecEmp emp =(com.onedec.admin.entity.OnedecEmp) request.getSession().getAttribute("emp");
        final Integer empId = emp.getEmpId();
        final ResponseEntity<List<Map<String,Object>>> schedule = scheduleClient.selectSchedule(empId+"");
        return new ResponseEntity(schedule);
    }
}